<template>
  <div id="userLoginView">
    <a-form :model="form" :style="{ width: '600px' }" @submit="handleSubmit">
      <a-form-item
        field="userAccount"
        tooltip="Please enter userAccount"
        label="userAccount"
        class="input"
      >
        <a-input
          v-model="form.userAccount"
          placeholder="please enter your userAccount..."
        />
      </a-form-item>

      <a-form-item field="userPassword" label="Post">
        <a-input-password
          v-model="form.userPassword"
          placeholder="please enter your userPassword..."
        />
      </a-form-item>

      <a-form-item class="sub">
        <a-button html-type="submit">Submit</a-button>
      </a-form-item>
    </a-form>
  </div>
</template>

<script setup lang="ts">
import { reactive } from "vue";
import { UserControllerService, UserLoginRequest } from "../../../generated";
import message from "@arco-design/web-vue/es/message";
import { useRouter } from "vue-router";
import { useUserStore } from "@/store/user";
import * as stream from "stream";

const router = useRouter();

const store = useUserStore();

const form = reactive({
  userAccount: "xiaopihai",
  userPassword: "12345678",
} as UserLoginRequest);
const handleSubmit = async (data: any) => {
  const res = await UserControllerService.userLoginUsingPost(form);
  if (res.code === 0) {
    //登录成功就跳转到主页

    await store.getLoginUser();

    router.push({
      path: "/",
      replace: true,
    });
  } else {
    message.error("failed!" + res.message);
  }
};
</script>

<style scoped>
.sub {
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>
